<!--
* description: 客户档案--车辆档案查询
* author:shensai
* createdDate: 2021.1.21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
      :callback-obj="callbackObj"
    />
  
      <edit
      v-if="editPopupsVisible"
      :key="editPopupsKey"
      :popups-visible="editPopupsVisible"
      :data-for-form="editRowData"
      :popups-state="editPopupsState"
      :title-name="titleName"
      @close="close"
      @save="save"
    /> 
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { orgApis } from '@/api/vesalesapi.js'
import OneTableTemplate from '@/components/templates/oneTable'
import { exportExcel } from '@/utils/getTimeString'
import edit from './edit'

import Vue from 'vue'
export default {
  name: 'vehicleFileQuery',
  components: {
    OneTableTemplate,
     edit
  },
  mixins: [oneTableWithViewTemplateMixins],
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, 'supplierMessage-edit'], () => {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path
    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])
    return {
       titleName: '',
      editRowData: {},
      editPopupsState: '',
      editPopupsVisible: false,
      // 网格查询API配置对象
      apiConfig: orgApis.orderinvoiceQuery,
      // 动态组件-按钮
      tableButtons: [
          
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          name: 'search', // 按钮图标样式
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey4',
          type: '',
          size: 'small',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          name: 'reset',
          position: 'right' // 重置
        },
        {
          compKey: 'btnKey5',
          type: '',
          size: 'small',
          clickEvent: () => this.exportExcelAll(),
          text: '导出', // err
          name: 'export',
          position: 'left'
        },
      
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            // 显示组件
            {
              compKey: 'compKey1',
              labelName: '车系',
              codeField: 'saleOrderCode',
              isMul: false,
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '车型：',
              codeField: 'custName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '车牌号',
              codeField: 'custTel',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
         {
              compKey: 'compKey11',
              labelName: '交付日期：',
              codeField: 'invoiceDate',
              component: () => import('@/components/org/datePicker/datePicker.vue'),
              type: 'inputText',
              isMul: false,
              isMust: true,
              
            }
           
          ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
               {
              prop: 'controlBtn1',
              label: '操作',
              minWidth: 180,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '查看',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                }
              ]
            },
            {
              prop: 'saleOrderCode',
              label: 'VIN码'
            },
           
            {
              prop: 'empName',
              label: '车系'
            },
            {
              prop: 'signatoryName',
              label: '车型'
            },
            {
              prop: 'custCardNo',
              label: '车牌号'
            },
             {
              prop: 'signatoryName',
              label: '车身颜色'
            },
            {
              prop: 'custCardNo',
              label: '交付日期'
            },
             {
              prop: 'signatoryName',
              label: '交付门店'
            },
       
           
          ],
      formField: {
        saleOrderCode: '',
        custName: '',
        custTel: '',
        invoiceApplyStatusId: '',
        vin: '',
        deliveryDlrId: '',
        empId: '',
        erpBookStatusId: '',
        signatoryName: '',
        signatoryPhone: '',
        invoiceDate: ''
      },
      // 是否使用刷新Key的方式刷新弹窗
      resetDialogKey: false,
      // 单表格模版页面组件回调事件
      callbackObj: {
        // // 手动勾选时
        // onCheckSelect: (selection, row) => {
        //   // 清除所有选中
        //   this.$refs.multipleTable.$refs.multipleTable.clearSelection()
        //   if (selection.length === 0) return
        //   // 将当前点击项选中
        //   this.$refs.multipleTable.$refs.multipleTable.toggleRowSelection(row, true)
        // },
        // // 当选择项发生变化时会触发该事件（多选时）
        // onCheckSelectChange: (selection) => {
        //   if (selection.length === 1) {
        //     this.editRowData = selection[0]
        //   }
        // }
      }
    }
  },
  mounted() {
    // this.queryTable(1)
       this.$refs.multipleTable.list = [{
      index: 1
    }]
  },
  methods: {
    // exportExcelAll() {
    //   exportExcel(this.formField, orgApis.orderinvoiceExport.APIUrl, orgApis.orderinvoiceExport.ServiceCode, '订单开票')
    // },
    // save(val) {
    //   // this.closeinvoice()
    // }
     // 编辑
    edit(index, popstatus) {
      // const rowData = this.$refs['multipleTable'].list[index]
      // const loading = this.$loading({
      //   text: '正在加载数据......'
      // })
      // this.getSubData(rowData.insaleOrderId)
      //   .then(res => {
      //     rowData.carInfo = res
      //     this.clickRowsData = rowData
      //     this.popstate = popstatus || 'edit'
      //     loading.close()
      //     this.showdia = true
      //   }).catch(err => {
      //     console.log(err)
      //   })
      this.editPopupsVisible=true
    },
    // selectRowsData(rowdata){
    //
    // },
    // 打开编辑窗 获取子表数据
    getSubData(insaleOrderId) {
      return new Promise((resolve, reject) => {
        this.$requestAPI({
          apiUrl: api.getSubDatas.APIUrl,
          variables: {
            insaleOrderId
          }
        }).then(response => {
          if (response.result === '1') {
            resolve(response.rows)
          }
        }).catch(err => {
          reject(err)
        })
      })
    },
  }
}
</script>
